import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {TrainTeacherVO} from "@interface/index";
import {ParentService} from "@train/parent/parent.service";
import {ActivatedRoute, Params} from "@angular/router";
import {ImageServeService} from "@shared/service/image/image-serve.service";

@Component({
  selector: 'seed-class-teacher',
  templateUrl: './class-teacher.component.html',
  styleUrls: ['./class-teacher.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class ParentClassTeacherComponent implements OnInit {
  public teachers: Array<TrainTeacherVO> = [];
  public curTeacherInfo: TrainTeacherVO;
  public teacherIndex = 0;
  public teacherCommentInfo = {
    classId: 0,
    studentId: 0,
    page: 1,
    rows: 10
  };
  public dataStore = {
    roleType: ['主教练', '助理教练', '课程顾问'],
    defaultAvatar: ''
  };

  constructor(private parentService: ParentService,
              public imageService: ImageServeService,
              private activatedRoute: ActivatedRoute) {
    this.activatedRoute.params.subscribe((param: Params) => {
      this.teacherCommentInfo.classId = param['classId'];
      this.dataStore.defaultAvatar = this.imageService.getAvatarIcon();
    });
  }

  /**
   * @author guoqs1331
   * @time 2018/1/29
   * @description 获取教练列表
   */
  trainCourseTeacherInfoByClassId() {
    this.parentService.trainCourseTeacherInfoByClassId(this.teacherCommentInfo.classId).subscribe((res) => {
      if (res['result'] === '0' && res.data) {
        this.teachers = res.data;
        // this.teachers = [...this.teachers];
        this.curTeacherInfo = this.teachers[0];
      }
    });
  }

  /**
   * @author guoqs1331
   * @time 2018/1/29
   * @description 选择教练
   */
  chooseTeacher(teacher, index) {
    this.teacherIndex = index;
    this.curTeacherInfo = this.teachers[index];
  }

  ngOnInit() {
    this.trainCourseTeacherInfoByClassId();
  }

}
